package com.usb;


import javax.usb.UsbDevice;
import javax.usb.UsbHostManager;
import javax.usb.UsbHub;
import java.util.List;

/**
 * @ClassName: USBDemo
 * @Author: ZhangYue26
 * @Description: 读取USB相关设备
 * @Date: 2020-09-12
 */
public class USBDemo {
    public static void main(String[] args) throws Exception {
        UsbHub rootUsbHub = UsbHostManager.getUsbServices()
                .getRootUsbHub();
        List attachedUsbDevices = rootUsbHub.getAttachedUsbDevices();
        for (Object attachedUsbDevice : attachedUsbDevices) {
            UsbDevice usbDevice = (UsbDevice) attachedUsbDevice;
            System.out.println(usbDevice.getSerialNumberString());

        }

    }
}
